﻿using System.Collections.Generic;
using System.Linq;

namespace FlowControl
{
    class FlowContainerBase : FlowBase, IContainer
    {
        protected List<IFlowBase> childs;
        public FlowContainerBase()
        {
            childs = new List<IFlowBase>();
        }

        public void AddFlow(IFlowBase flow)
        {
            childs.Add(flow);
        }

        public void RemoveFlow(IFlowBase flow)
        {
            childs.Remove(flow);
        }

        public int NumChildren
        {
            get { return childs.Count; }
        }

        public List<IFlowBase> GetChilds()
        {
            List<IFlowBase> flows = new List<IFlowBase>();
            for (int i = 0; i < childs.Count; i++)
            {
                IFlowBase flow = childs[i];
                if (flow is IContainer)
                {
                    IContainer temp = flow as IContainer;
                    flows.Concat(temp.GetChilds());
                }
                else
                {
                    flows.Add(flow);
                }
            }
            return flows;
        }
    }
}